/*
 * @页面名称: 过滤权限操作按钮和修改按钮点击的状态
 * @描述:先过滤没有权限操作的按钮,然后根据业务确定哪些按钮是否可点击
 * @作者:
 * @Date:
 */

import { buttonList, fulltextButton, childButtonList } from "@/enums/dynamicButton";
import { cloneDeep } from "lodash-es";
import { useDynamicButtonStore } from "@/stores/modules/dynamicButton";
export class ButtonStatus {
  preVerb: any[];
  preVerb2: any[];
  preVerb3: any[];
  dynamicButton: any;
  constructor() {
    // 初始状态按钮;
    this.preVerb = buttonList;
    this.preVerb2 = fulltextButton;
    this.preVerb3 = childButtonList;
    this.dynamicButton = useDynamicButtonStore();
  }
  /**
   * @名字:主要按钮
   * @详情:
   * @参数:
   * @返回值:
   */
  filterButtonAuth(statusList: any[]) {
    const preVerb1_temp: any[] = cloneDeep(this.preVerb); // 深度克隆对象
    if (statusList && statusList.length > 0) {
      const verb1: any[] = [];
      preVerb1_temp.forEach(item => {
        const tempObj = {
          title: item.title,
          icon: item.icon,
          disabled: item.disabled,
          show: item.show,
          alias: item.alias
        };
        if (item.list) {
          item.list = item.list.filter((v: any) => statusList.includes(v.title));
          verb1.push({
            title: item.title,
            icon: item.icon,
            list: item.list
          });
        }
        statusList.forEach(item2 => {
          if (item.title === item2) {
            verb1.push(tempObj);
          }
        });
      });
      this.dynamicButton.SetButtonList(verb1);
    } else {
      this.dynamicButton.SetButtonList([]);
    }
  }
  /**
   * @名字:全文按钮
   * @详情:
   * @参数:
   * @返回值:
   */
  filterFulltextButtonAuth(statusList: any[]) {
    const preVerb1_temp2: any[] = cloneDeep(this.preVerb2); // 深度克隆对象
    // 过滤出所有符合权限的按钮
    // const filteredArray = this.preVerb.filter(item => statusList.includes(item.title));
    // return filteredArray;
    if (statusList && statusList.length > 0) {
      const verb2: any[] = [];
      preVerb1_temp2.forEach(item => {
        const tempObj = {
          title: item.title,
          icon: item.icon,
          disabled: item.disabled,
          show: item.show,
          alias: item.alias
        };
        statusList.forEach(item2 => {
          if (item.title === item2) {
            verb2.push(tempObj);
          }
        });
      });
      this.dynamicButton.SetFulltextList(verb2);
    } else {
      this.dynamicButton.SetFulltextList([]);
    }
  }
  /**
   * @名字:子级表格按钮
   * @详情:
   * @参数:
   * @返回值:
   */
  filterChildButtonAuth(statusList: any[]) {
    const preVerb3_temp: any[] = cloneDeep(this.preVerb3); // 深度克隆对象
    if (statusList && statusList.length > 0) {
      const verb3: any[] = [];
      preVerb3_temp.forEach(item => {
        const tempObj = {
          title: item.title,
          icon: item.icon,
          disabled: item.disabled,
          show: item.show,
          alias: item.alias
        };
        if (item.list) {
          item.list = item.list.filter((v: any) => statusList.includes(v.title));
          verb3.push({
            title: item.title,
            icon: item.icon,
            list: item.list
          });
        }
        statusList.forEach(item2 => {
          if (item.title === item2) {
            verb3.push(tempObj);
          }
        });
      });
      this.dynamicButton.SetChildButtonList(verb3);
    } else {
      this.dynamicButton.SetChildButtonList([]);
    }
  }
}
